package o;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Build.VERSION;
import android.provider.Settings.Global;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import o.fnb.c;

public class fna {
    private static final Method ˎ;
    private static final Method ॱ;
    private boolean ʻ = false;
    private boolean ʼ = false;
    private boolean ʽ = false;
    private int ˊ = 0;
    private boolean ˊॱ = false;
    private final Rect ˋ = new Rect();
    private boolean ˋॱ = false;
    private final View ˏ;
    private final Runnable ॱˊ = new 4(this);
    private final Rect ॱॱ = new Rect();
    private int ᐝ = 0;

    static {
        Method declaredMethod;
        Method method = null;
        if (VERSION.SDK_INT >= 28) {
            try {
                declaredMethod = Class.forName("huawei.android.widget.RadiusSizeUtils").getDeclaredMethod("getRadiusSize", new Class[]{Context.class});
            } catch (ClassNotFoundException e) {
                declaredMethod = e;
                declaredMethod = "HwWidgetSafeInsets";
                Log.w(declaredMethod, "getRadiusSize ClassNotFoundException");
            } catch (NoSuchMethodException e2) {
                declaredMethod = e2;
                declaredMethod = "HwWidgetSafeInsets";
                Log.w(declaredMethod, "getRadiusSize NoSuchMethodException");
            } finally {
                method = 
/*
Method generation error in method: o.fna.<clinit>():void
jadx.core.utils.exceptions.CodegenException: Error generate insn: ?: MERGE  (r5_3 'method' java.lang.reflect.Method) = (r5_0 'method' java.lang.reflect.Method), (r0_18 'declaredMethod' java.lang.reflect.Method) in method: o.fna.<clinit>():void
	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:226)
	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:203)
	at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:100)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:50)
	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:87)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:53)
	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:93)
	at jadx.core.codegen.RegionGen.makeTryCatch(RegionGen.java:297)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:63)
	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:87)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:53)
	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:93)
	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:118)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:57)
	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:87)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:53)
	at jadx.core.codegen.RegionGen.makeSimpleRegion(RegionGen.java:87)
	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:53)
	at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:183)
	at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:328)
	at jadx.core.codegen.ClassGen.addMethods(ClassGen.java:265)
	at jadx.core.codegen.ClassGen.addClassBody(ClassGen.java:228)
	at jadx.core.codegen.ClassGen.addClassCode(ClassGen.java:118)
	at jadx.core.codegen.ClassGen.makeClass(ClassGen.java:83)
	at jadx.core.codegen.CodeGen.visit(CodeGen.java:19)
	at jadx.core.ProcessClass.process(ProcessClass.java:43)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
Caused by: jadx.core.utils.exceptions.CodegenException: MERGE can be used only in fallback mode
	at jadx.core.codegen.InsnGen.fallbackOnlyInsn(InsnGen.java:530)
	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:514)
	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:220)
	... 27 more

*/

                public fna(View view) {
                    this.ˏ = view;
                }

                public boolean ˎ() {
                    return this.ˊ == 2;
                }

                public void ˎ(Context context, AttributeSet attributeSet) {
                    if (context == null || attributeSet == null) {
                        Log.w("HwWidgetSafeInsets", "parse cutout mode error");
                        return;
                    }
                    TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, c.ˋ);
                    this.ˊ = obtainStyledAttributes.getInt(c.ˏ, 0);
                    obtainStyledAttributes.recycle();
                }

                public void ˎ(int i, int i2, int i3, int i4) {
                    ˊ(new Rect(i, i2, i3, i4));
                }

                public void ˊ(Rect rect) {
                    if (!ॱ(this.ˏ) || (this.ᐝ & 1) != 0) {
                        return;
                    }
                    if (this.ˊॱ) {
                        this.ˋॱ = true;
                        return;
                    }
                    this.ॱॱ.set(rect);
                    this.ˊॱ = true;
                    this.ᐝ |= 2;
                }

                public void ॱ(WindowInsets windowInsets) {
                    if (VERSION.SDK_INT >= 28) {
                        Rect ˋ;
                        if (ॱ != null) {
                            ˋ = ˋ(windowInsets);
                        } else {
                            ˋ = ˊ(windowInsets);
                        }
                        if (ˋ == null) {
                            ˋ = new Rect();
                        }
                        boolean ˎ = ˎ(this.ˏ);
                        if (!this.ˋ.equals(ˋ) || this.ʼ != ˎ) {
                            this.ˋ.set(ˋ);
                            this.ᐝ |= 2;
                            this.ʼ = ˎ;
                            if (this.ˏ != null) {
                                this.ˏ.removeCallbacks(this.ॱˊ);
                                this.ˏ.post(this.ॱˊ);
                            }
                        }
                    }
                }

                public void ˊ(View view, Rect rect, boolean z) {
                    if (view != null && rect != null && !ˎ() && (this.ᐝ & 2) != 0) {
                        this.ᐝ |= 1;
                        view.setPadding(rect.left, rect.top, rect.right, rect.bottom);
                        this.ᐝ &= -2;
                        if (z) {
                            this.ˏ.removeCallbacks(this.ॱˊ);
                            this.ˏ.post(this.ॱˊ);
                            this.ᐝ &= -3;
                        }
                    }
                }

                public void ˊ(boolean z) {
                    if ((this.ᐝ & 2) != 0) {
                        ˊ(this.ˏ, ˋ(this.ˏ), z);
                    }
                }

                public Rect ˋ(View view) {
                    return ˊ(view, this.ॱॱ);
                }

                public Rect ˊ(View view, Rect rect) {
                    int i = 1;
                    Rect rect2 = new Rect();
                    if (view == null || rect == null) {
                        return rect2;
                    }
                    int i2;
                    rect2.set(rect);
                    if (this.ʽ || this.ʻ || ˊ()) {
                        i2 = 0;
                    } else {
                        i2 = 1;
                    }
                    if (ˎ() || r0 != 0) {
                        return rect2;
                    }
                    Rect rect3 = new Rect();
                    Rect rect4 = new Rect();
                    int[] iArr = new int[2];
                    view.getLocationInWindow(iArr);
                    rect3.set(iArr[0], iArr[1], iArr[0] + view.getWidth(), iArr[1] + view.getHeight());
                    View rootView = view.getRootView();
                    if (rootView == null) {
                        return rect2;
                    }
                    rootView.getLocationInWindow(iArr);
                    rect4.set(iArr[0], iArr[1], iArr[0] + rootView.getWidth(), iArr[1] + rootView.getHeight());
                    ˎ(rect, rect2, rect3, rect4);
                    boolean ˋ = ˋ(view.getContext());
                    if (this.ʻ) {
                        if (!ˋ || this.ˋ.top <= 0 || rect3.top >= this.ˋ.top) {
                            i = 0;
                        }
                        if (i != 0) {
                            rect2.top = rect3.top + view.getPaddingTop() < this.ˋ.top ? this.ˋ.top : view.getPaddingTop();
                        } else if (this.ˋॱ) {
                            rect2.top = view.getPaddingTop();
                        }
                    }
                    if (this.ʽ && ˋ) {
                        i2 = ˊ(view);
                        if (i2 > 0) {
                            rect2.bottom = i2 + rect.bottom;
                        }
                    }
                    return rect2;
                }

                private void ˎ(Rect rect, Rect rect2, Rect rect3, Rect rect4) {
                    if (this.ˊ == 1) {
                        if (this.ˋ.left > 0) {
                            rect2.left = rect.left + this.ˋ.left;
                        }
                        if (this.ˋ.right > 0) {
                            rect2.right = rect.right + this.ˋ.right;
                            return;
                        }
                        return;
                    }
                    if (this.ˋ.left > 0 && rect3.left < this.ˋ.left) {
                        rect2.left = rect.left + this.ˋ.left;
                    }
                    if (this.ˋ.right > 0 && rect4.right - this.ˋ.right < rect3.right) {
                        rect2.right = rect.right + this.ˋ.right;
                    }
                }

                private int ˊ(View view) {
                    if (view == null) {
                        return 0;
                    }
                    Context context = view.getContext();
                    if (context == null) {
                        return 0;
                    }
                    int ˎ = ˎ(context);
                    if (ˎ <= 0) {
                        return 0;
                    }
                    int[] iArr = new int[2];
                    view.getLocationOnScreen(iArr);
                    WindowManager windowManager = (WindowManager) context.getSystemService("window");
                    DisplayMetrics displayMetrics = new DisplayMetrics();
                    windowManager.getDefaultDisplay().getRealMetrics(displayMetrics);
                    return ((iArr[1] + view.getMeasuredHeight()) + ˎ) - displayMetrics.heightPixels;
                }

                private boolean ˎ(View view) {
                    if (view == null || Global.getInt(view.getContext().getContentResolver(), "navigationbar_is_min", 0) != 0) {
                        return false;
                    }
                    return true;
                }

                public void ˎ(boolean z) {
                    this.ʻ = z;
                }

                public void ˏ(boolean z) {
                    this.ʽ = z;
                }

                private boolean ˋ(Context context) {
                    int rotation;
                    if (context != null) {
                        WindowManager windowManager = (WindowManager) context.getSystemService("window");
                        if (windowManager != null) {
                            rotation = windowManager.getDefaultDisplay().getRotation();
                            return rotation != 0 || rotation == 2;
                        }
                    }
                    rotation = 0;
                    if (rotation != 0) {
                    }
                }

                private static Rect ˋ(WindowInsets windowInsets) {
                    Rect rect = new Rect();
                    if (windowInsets == null || VERSION.SDK_INT < 28) {
                        return rect;
                    }
                    try {
                        Rect rect2;
                        if (ॱ != null) {
                            Object invoke = ॱ.invoke(null, new Object[]{windowInsets});
                            if (invoke != null || (invoke instanceof Rect)) {
                                rect2 = (Rect) invoke;
                                return rect2;
                            }
                        }
                        rect2 = rect;
                        return rect2;
                    } catch (IllegalAccessException e) {
                        Log.e("HwWidgetSafeInsets", "getDisplaySafeInsets IllegalAccessException");
                        return rect;
                    } catch (InvocationTargetException e2) {
                        Log.e("HwWidgetSafeInsets", "getDisplaySafeInsets InvocationTargetException");
                        return rect;
                    }
                }

                private static Rect ˊ(WindowInsets windowInsets) {
                    Rect rect = new Rect();
                    if (windowInsets != null && VERSION.SDK_INT == 28) {
                        DisplayCutout displayCutout = windowInsets.getDisplayCutout();
                        if (displayCutout != null) {
                            rect.set(displayCutout.getSafeInsetLeft(), 0, displayCutout.getSafeInsetRight(), 0);
                        }
                    }
                    return rect;
                }

                private static int ˎ(Context context) {
                    try {
                        int intValue;
                        if (ˎ != null) {
                            intValue = ((Integer) ˎ.invoke(null, new Object[]{context})).intValue();
                        } else {
                            intValue = 0;
                        }
                        return intValue;
                    } catch (IllegalAccessException e) {
                        Log.w("HwWidgetSafeInsets", "getRadiusSize IllegalAccessException");
                        return 0;
                    } catch (InvocationTargetException e2) {
                        Log.w("HwWidgetSafeInsets", "getRadiusSize InvocationTargetException");
                        return 0;
                    }
                }

                private boolean ˊ() {
                    if (this.ˋ == null) {
                        return false;
                    }
                    if (this.ˋ.left > 0 || this.ˋ.right > 0) {
                        return true;
                    }
                    return false;
                }

                private boolean ॱ(View view) {
                    if (view == null) {
                        return false;
                    }
                    if (VERSION.SDK_INT >= 19) {
                        return view.isAttachedToWindow();
                    }
                    if (view.getWindowToken() != null) {
                        return true;
                    }
                    return false;
                }
            }
